package action.concreteActions;

import grammer.WeatherSubject;
import grammer.components.WeatherEnum;
import timer.Timer;
import weather.CurrentWeather;
import action.ExecuteActionInterface;

public class ChangeWeatherAction extends ExecuteActionInterface {
	private WeatherEnum nextWeaher;
	private int type=0;
	private int value=0;

	public ChangeWeatherAction(Timer executeTime, WeatherSubject w) {
		super(executeTime);
		setOwner("Weather");
		nextWeaher = w.getSubject();
		type=0;
		value=0;
		if (nextWeaher==WeatherEnum.TEMP_C)
		{
			type=1;
			value=Integer.parseInt(w.getValue().substring(0,w.getValue().length()-1));
		}
	}

	@Override
	public int execute() {
		if(type==0){
			CurrentWeather.getInstance().setWeather(nextWeaher);
		}else
		{
			CurrentWeather.getInstance().setTemperature(value);
		}
		return 0;
	}

	@Override
	public int getEndTimer() {
		return executeTime.getTime();
	}

	@Override
	public int getExecuteTimer() {
		return executeTime.getTime();
	}

	@Override
	public int getStartTimer() {
		return executeTime.getTime();
	}
}
